package com.qfedu.stussm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.stussm.dao.RestDao;
import com.qfedu.stussm.entity.News;
import com.qfedu.stussm.entity.Rest;
import com.qfedu.stussm.service.intf.RestService;
import com.qfedu.stussm.vo.PageBeanVo;
import com.qfedu.stussm.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RestServiceImpl implements RestService {
    @Autowired
    private RestDao restDao;
    @Override
    public int add(Rest rest) {
        return restDao.add(rest);
    }

    @Override
    public PageBeanVo selectAll(int page, int limit) {
        PageHelper.startPage(page, limit);
        PageInfo<Rest> newsPageInfo = new PageInfo<>(restDao.selectAll());
        return new PageBeanVo(newsPageInfo.getTotal(), newsPageInfo.getList());
    }

    @Override
    public R update(Rest rest) {
        if (restDao.update(rest) > 0) {
            return R.ok();
        } else {
            return R.fail();
        }
    }

    @Override
    public R del(int id) {
        if (restDao.del(id) > 0) {
            return R.ok();
        } else {
            return R.fail();
        }
    }
}
